package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.SmsSendDetail;
import com.ruoyi.web.service.ISmsSendDetailService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 短信发送明细Controller
 *
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/smsSendDetail")
@AllArgsConstructor
public class SmsSendDetailController extends BaseController {
    private final ISmsSendDetailService smsSendDetailService;

    /**
     * 查询短信发送明细列表
     */
    @PreAuthorize("@ss.hasPermi('smsSendDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsSendDetail smsSendDetail) {
        startPage();
        List<SmsSendDetail> list = smsSendDetailService.selectSmsSendDetailList(smsSendDetail);
        return getDataTable(list);
    }

    /**
     * 导出短信发送明细列表
     */
    @PreAuthorize("@ss.hasPermi('smsSendDetail:export')")
    @Log(title = "短信发送明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsSendDetail smsSendDetail) {
        List<SmsSendDetail> list = smsSendDetailService.selectSmsSendDetailList(smsSendDetail);
        ExcelUtil<SmsSendDetail> util = new ExcelUtil<SmsSendDetail>(SmsSendDetail.class);
        util.exportExcel(response, list, "短信发送明细数据");
    }

    /**
     * 获取短信发送明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('smsSendDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(smsSendDetailService.selectSmsSendDetailById(id));
    }

    /**
     * 修改短信发送明细
     */
    @PreAuthorize("@ss.hasPermi('smsSendDetail:edit')")
    @Log(title = "短信发送明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsSendDetail smsSendDetail) {
        return toAjax(smsSendDetailService.updateSmsSendDetail(smsSendDetail));
    }

    /**
     * 删除短信发送明细
     */
    @PreAuthorize("@ss.hasPermi('smsSendDetail:remove')")
    @Log(title = "短信发送明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(smsSendDetailService.deleteSmsSendDetailByIds(ids));
    }
}
